<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of tt_minres_selfprec2</title>
  <meta name="keywords" content="tt_minres_selfprec2">
  <meta name="description" content="Computation of the approximate TT-matrix inverse using self-prec method">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html v1.5 &copy; 2003-2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../../m2html.css">
</head>
<body>
<a name="_top"></a>
<div><a href="../../index.html">Home</a> &gt;  <a href="#">tt2</a> &gt; <a href="index.html">exp</a> &gt; tt_minres_selfprec2.m</div>

<!--<table width="100%"><tr><td align="left"><a href="../../index.html"><img alt="<" border="0" src="../../left.png">&nbsp;Master index</a></td>
<td align="right"><a href="index.html">Index for tt2/exp&nbsp;<img alt=">" border="0" src="../../right.png"></a></td></tr></table>-->

<h1>tt_minres_selfprec2
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>Computation of the approximate TT-matrix inverse using self-prec method</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="box"><strong>function [X]=tt_minres_selfprec2(A,  eps, varargin) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre class="comment">Computation of the approximate TT-matrix inverse using self-prec method
   [X]=TT_MINRES_SELFPREC2(A,EPS,OPTIONS) Computation of the approximate
   TT-matrix inverse using Saad self-prec method. Options are provided 
   in form 'PropertyName1',PropertyValue1,'PropertyName2',PropertyValue2 
   and so on. The parameters are set to default (in brackets in the 
   following) The list of option names and default values are:
       o matvec - type of the local matvec [ {mm+compr} | mmk2 ]
       o max_rank - maximal TT-rank bound [1000]
       o prec_type - left or right inversion [ {left} | right ]
       o maxit - maximal number of iterations [10]
       o tol - the requested inversion tolerance [EPS]


 TT-Toolbox 2.2, 2009-2012

This is TT Toolbox, written by Ivan Oseledets et al.
Institute of Numerical Mathematics, Moscow, Russia
webpage: http://spring.inm.ras.ru/osel

For all questions, bugs and suggestions please mail
ivan.oseledets@gmail.com
---------------------------</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../../matlabicon.gif)">
<li><a href="../../tt2/@qtt_tucker/dot.html" class="code" title="function [p] = dot(qt1,qt2, do_qr)">dot</a>	Dot product of two QTT-Tuckers</li><li><a href="../../tt2/@qtt_tucker/norm.html" class="code" title="function [nrm] = norm(tt)">norm</a>	Frobenius norm of the QTT-Tucker</li><li><a href="../../tt2/@qtt_tucker/rank.html" class="code" title="function [r]=rank(a,varargin)">rank</a>	Computes ranks of the QTT-Tucker tensor</li><li><a href="../../tt2/@qtt_tucker/round.html" class="code" title="function [tt]=round(tt,varargin)">round</a>	Approximate QTT-Tucker with another one with specified accuracy</li><li><a href="../../tt2/@tt_matrix/conj.html" class="code" title="function [b]=conj(a)">conj</a>	Complex conjugate of a TT-matrix</li><li><a href="../../tt2/@tt_matrix/dot.html" class="code" title="function [p] = dot(tt1,tt2)">dot</a>	Frobenius dot product of two TT-matrices</li><li><a href="../../tt2/@tt_matrix/ndims.html" class="code" title="function d = ndims(tt)">ndims</a>	Number of dimensions of a TT-matrix</li><li><a href="../../tt2/@tt_matrix/norm.html" class="code" title="function [nrm] = norm(t,varargin)">norm</a>	Matrix norm of the TT-matrix</li><li><a href="../../tt2/@tt_matrix/rank.html" class="code" title="function [r]=rank(a,varargin)">rank</a>	All or individual TT-ranks of a TT-matrix</li><li><a href="../../tt2/@tt_matrix/round.html" class="code" title="function [tt]=round(tt,eps,rmax)">round</a>	Approximate TT-matrix with another one with specified accuracy</li><li><a href="../../tt2/@tt_matrix/tt_matrix.html" class="code" title="function t = tt_matrix(varargin)">tt_matrix</a>	TT_matrix class constructor</li><li><a href="../../tt2/@tt_tensor/conj.html" class="code" title="function [tt1]=conj(tt)">conj</a>	Compute a complex conjugate of TT-tensor</li><li><a href="../../tt2/@tt_tensor/dot.html" class="code" title="function [p] = dot(tt1,tt2,do_qr)">dot</a>	Dot  product of two TT tensors</li><li><a href="../../tt2/@tt_tensor/ndims.html" class="code" title="function d = ndims(tt)">ndims</a>	Number of dimensions of a tensor</li><li><a href="../../tt2/@tt_tensor/norm.html" class="code" title="function [nrm] = norm(tt)">norm</a>	Frobenius norm of the TT-tensor</li><li><a href="../../tt2/@tt_tensor/rank.html" class="code" title="function [r]=rank(a,varargin)">rank</a>	Returns TT-ranks of the given tensor in TT-format</li><li><a href="../../tt2/@tt_tensor/round.html" class="code" title="function [tt]=round(tt,varargin)">round</a>	Approximate TT-tensor with another one with specified accuracy</li><li><a href="../../tt2/@tt_tensor/tt_tensor.html" class="code" title="function t = tt_tensor(varargin)">tt_tensor</a>	TT-tensor constructor</li><li><a href="../../tt2/core/tt_eye.html" class="code" title="function [e]=tt_eye(n,varargin)">tt_eye</a>	Identity matrix in the TT-format</li><li><a href="tt_mmk2.html" class="code" title="function [ttm12] = tt_mmk2(ttm1, ttm2, eps, max_r, max_swp)">tt_mmk2</a>	DMRG/Krylov matrix-by-matrix multiplication</li></ul>
This function is called by:
<ul style="list-style-image:url(../../matlabicon.gif)">
</ul>
<!-- crossreference -->



<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [X]=tt_minres_selfprec2(A,  eps, varargin)</a>
0002 <span class="comment">%Computation of the approximate TT-matrix inverse using self-prec method</span>
0003 <span class="comment">%   [X]=TT_MINRES_SELFPREC2(A,EPS,OPTIONS) Computation of the approximate</span>
0004 <span class="comment">%   TT-matrix inverse using Saad self-prec method. Options are provided</span>
0005 <span class="comment">%   in form 'PropertyName1',PropertyValue1,'PropertyName2',PropertyValue2</span>
0006 <span class="comment">%   and so on. The parameters are set to default (in brackets in the</span>
0007 <span class="comment">%   following) The list of option names and default values are:</span>
0008 <span class="comment">%       o matvec - type of the local matvec [ {mm+compr} | mmk2 ]</span>
0009 <span class="comment">%       o max_rank - maximal TT-rank bound [1000]</span>
0010 <span class="comment">%       o prec_type - left or right inversion [ {left} | right ]</span>
0011 <span class="comment">%       o maxit - maximal number of iterations [10]</span>
0012 <span class="comment">%       o tol - the requested inversion tolerance [EPS]</span>
0013 <span class="comment">%</span>
0014 <span class="comment">%</span>
0015 <span class="comment">% TT-Toolbox 2.2, 2009-2012</span>
0016 <span class="comment">%</span>
0017 <span class="comment">%This is TT Toolbox, written by Ivan Oseledets et al.</span>
0018 <span class="comment">%Institute of Numerical Mathematics, Moscow, Russia</span>
0019 <span class="comment">%webpage: http://spring.inm.ras.ru/osel</span>
0020 <span class="comment">%</span>
0021 <span class="comment">%For all questions, bugs and suggestions please mail</span>
0022 <span class="comment">%ivan.oseledets@gmail.com</span>
0023 <span class="comment">%---------------------------</span>
0024 
0025 <span class="comment">% matvec='mmk2';</span>
0026 matvec=<span class="string">'mm+compr'</span>;
0027 max_rank=1000;
0028 prec_type=<span class="string">'left'</span>;
0029 tol=eps;
0030 maxit=10;
0031 
0032 <span class="keyword">for</span> i=1:2:length(varargin)-1
0033     <span class="keyword">switch</span> lower(varargin{i})
0034         <span class="keyword">case</span> <span class="string">'matvec'</span>
0035             matvec=varargin{i+1};
0036         <span class="keyword">case</span> <span class="string">'max_rank'</span>
0037             max_rank=lower(varargin{i+1});
0038         <span class="keyword">case</span> <span class="string">'prec_type'</span>
0039             prec_type=varargin{i+1};
0040         <span class="keyword">case</span> <span class="string">'maxit'</span>
0041             maxit=varargin{i+1};
0042         <span class="keyword">otherwise</span>
0043             error(<span class="string">'Unrecognized option: %s\n'</span>,varargin{i});
0044     <span class="keyword">end</span>
0045 <span class="keyword">end</span>
0046 
0047 
0048 <span class="comment">%d=max(size(A));</span>
0049 d=<a href="../../tt2/@tt_matrix/ndims.html" class="code" title="function d = ndims(tt)">ndims</a>(A);
0050 ns=A.n;
0051 <span class="comment">%ns=tt_size(A);</span>
0052 
0053 I=<a href="../../tt2/core/tt_eye.html" class="code" title="function [e]=tt_eye(n,varargin)">tt_eye</a>(ns, d); I=<a href="../../tt2/@tt_matrix/tt_matrix.html" class="code" title="function t = tt_matrix(varargin)">tt_matrix</a>(I);
0054 <span class="keyword">if</span> (strcmp(prec_type, <span class="string">'left'</span>))
0055    <span class="comment">% X=tt_scal(tt_transp(A), 1e-15);</span>
0056    X=(1e-15)*<a href="../../tt2/@tt_matrix/conj.html" class="code" title="function [b]=conj(a)">conj</a>(A');
0057 <span class="keyword">else</span>
0058   <span class="comment">%  X=tt_scal(I, 1e-150);</span>
0059    X=1e-150*I;
0060 <span class="keyword">end</span>;
0061 normf=<a href="../../tt2/@qtt_tucker/norm.html" class="code" title="function [nrm] = norm(tt)">norm</a>(I);
0062 <span class="comment">%normf=sqrt(tt_dot(tt_mat_to_vec(I), tt_mat_to_vec(I)));</span>
0063 err=1;
0064 err_old=2;
0065 sp=0;
0066 
0067 <span class="keyword">for</span> iout=1:maxit
0068     <span class="keyword">if</span> (strcmp(matvec, <span class="string">'mmk2'</span>))
0069         resid=<a href="tt_mmk2.html" class="code" title="function [ttm12] = tt_mmk2(ttm1, ttm2, eps, max_r, max_swp)">tt_mmk2</a>(A, X, eps, max_rank);
0070     <span class="keyword">else</span>
0071         <span class="comment">%resid=tt_mm(A,X);</span>
0072         resid=<a href="../../tt2/@qtt_tucker/round.html" class="code" title="function [tt]=round(tt,varargin)">round</a>(A*X,eps,max_rank*2);
0073         <span class="comment">%resid=tt_mat_compr(resid, eps,max_rank*2);</span>
0074     <span class="keyword">end</span>;
0075     <span class="comment">%resid=ttm_add(I, tt_scal(resid, -1));</span>
0076     resid=I-resid;
0077     
0078     <span class="keyword">if</span> (iout&gt;1)||(strcmp(prec_type, <span class="string">'left'</span>))
0079         <span class="keyword">if</span> (strcmp(matvec, <span class="string">'mmk2'</span>))
0080             Xresid=<a href="tt_mmk2.html" class="code" title="function [ttm12] = tt_mmk2(ttm1, ttm2, eps, max_r, max_swp)">tt_mmk2</a>(X, resid, eps,max_rank);
0081         <span class="keyword">else</span>
0082             <span class="comment">%Xresid=tt_mm(X,resid);</span>
0083             Xresid=<a href="../../tt2/@qtt_tucker/round.html" class="code" title="function [tt]=round(tt,varargin)">round</a>(X*resid,eps,max_rank*2);
0084             <span class="comment">%Xresid=tt_mat_compr(Xresid, eps,max_rank*2);</span>
0085             
0086         <span class="keyword">end</span>;
0087     <span class="keyword">else</span>
0088         Xresid=resid;
0089     <span class="keyword">end</span>;
0090     
0091     max_xrrank=max(<a href="../../tt2/@qtt_tucker/rank.html" class="code" title="function [r]=rank(a,varargin)">rank</a>(Xresid));
0092     
0093     <span class="keyword">if</span> (strcmp(prec_type, <span class="string">'left'</span>)) <span class="comment">% we use left preconditioner (igmres)</span>
0094         <span class="keyword">if</span> (strcmp(matvec, <span class="string">'mmk2'</span>))
0095             w=<a href="tt_mmk2.html" class="code" title="function [ttm12] = tt_mmk2(ttm1, ttm2, eps, max_r, max_swp)">tt_mmk2</a>(A, Xresid, eps,max_rank);
0096             w=<a href="tt_mmk2.html" class="code" title="function [ttm12] = tt_mmk2(ttm1, ttm2, eps, max_r, max_swp)">tt_mmk2</a>(X, w, eps,max_rank);
0097         <span class="keyword">else</span>
0098             w=<a href="../../tt2/@qtt_tucker/round.html" class="code" title="function [tt]=round(tt,varargin)">round</a>(A*Xresid,eps,max_rank);
0099             w=<a href="../../tt2/@qtt_tucker/round.html" class="code" title="function [tt]=round(tt,varargin)">round</a>(X*w,eps);
0100             <span class="comment">%w=tt_mm(A,Xresid);</span>
0101             <span class="comment">%w=tt_mat_compr(w, eps,max_rank);</span>
0102             <span class="comment">%w=tt_mm(X,w);</span>
0103 <span class="comment">%             w=tt_mat_compr(w, eps);</span>
0104         <span class="keyword">end</span>;
0105         <span class="comment">%w = tt_mat_to_vec(w);</span>
0106         <span class="comment">%beta=sqrt(tt_dot(tt_mat_to_vec(Xresid),tt_mat_to_vec(Xresid)));</span>
0107         beta=<a href="../../tt2/@qtt_tucker/norm.html" class="code" title="function [nrm] = norm(tt)">norm</a>(Xresid);
0108         wr=<a href="../../tt2/@qtt_tucker/dot.html" class="code" title="function [p] = dot(qt1,qt2, do_qr)">dot</a>(w,Xresid);
0109         <span class="comment">%wr = tt_dot(w, tt_mat_to_vec(Xresid));</span>
0110         ww=<a href="../../tt2/@qtt_tucker/dot.html" class="code" title="function [p] = dot(qt1,qt2, do_qr)">dot</a>(w,w);
0111         
0112         H=zeros(2,1);
0113         H(1,1)=wr/(beta^2);
0114         H(2,1)=sqrt(ww/(beta^2)-wr^2/(beta^4));
0115         rhs=H(1,1)*beta;
0116         
0117         y = rhs/(H'*H);
0118         err = err*<a href="../../tt2/@qtt_tucker/norm.html" class="code" title="function [nrm] = norm(tt)">norm</a>(H*y-[beta; 0])/beta; 
0119         y=y/beta;
0120         
0121 <span class="comment">%         y = tt_dot(w,w);</span>
0122 <span class="comment">%         if (y~=0)</span>
0123 <span class="comment">%             y = tt_dot(w, tt_mat_to_vec(Xresid))/y;</span>
0124 <span class="comment">%         else</span>
0125 <span class="comment">%             y=1;</span>
0126 <span class="comment">%         end;</span>
0127     <span class="keyword">else</span> <span class="comment">% Use right preconditioner and fgmres</span>
0128         <span class="keyword">if</span> (strcmp(matvec, <span class="string">'mmk2'</span>))
0129             w=<a href="tt_mmk2.html" class="code" title="function [ttm12] = tt_mmk2(ttm1, ttm2, eps, max_r, max_swp)">tt_mmk2</a>(A, Xresid, eps,max_rank);
0130         <span class="keyword">else</span>
0131             w=A*Xresid;
0132             w=<a href="../../tt2/@qtt_tucker/round.html" class="code" title="function [tt]=round(tt,varargin)">round</a>(w,eps);
0133 <span class="comment">%             w=tt_mat_compr(w, eps);</span>
0134         <span class="keyword">end</span>;
0135         w=<a href="../../tt2/@tt_tensor/tt_tensor.html" class="code" title="function t = tt_tensor(varargin)">tt_tensor</a>(w);
0136         <span class="comment">%w = tt_mat_to_vec(w);</span>
0137         beta=<a href="../../tt2/@qtt_tucker/norm.html" class="code" title="function [nrm] = norm(tt)">norm</a>(resid);
0138         <span class="comment">%beta=sqrt(tt_dot(tt_mat_to_vec(resid),tt_mat_to_vec(resid)));</span>
0139         wr=<a href="../../tt2/@qtt_tucker/dot.html" class="code" title="function [p] = dot(qt1,qt2, do_qr)">dot</a>(w,<a href="../../tt2/@tt_tensor/tt_tensor.html" class="code" title="function t = tt_tensor(varargin)">tt_tensor</a>(resid));
0140         ww=<a href="../../tt2/@qtt_tucker/dot.html" class="code" title="function [p] = dot(qt1,qt2, do_qr)">dot</a>(w,w);
0141         <span class="comment">%wr = tt_dot(w, tt_mat_to_vec(resid));</span>
0142         <span class="comment">%ww = tt_dot(w,w);</span>
0143         
0144         H=zeros(2,1);
0145         H(1,1)=wr/(beta^2);
0146         H(2,1)=sqrt(ww/(beta^2)-wr^2/(beta^4));
0147         rhs=H(1,1)*beta;
0148         
0149         y = rhs/(H'*H);
0150         err = <a href="../../tt2/@qtt_tucker/norm.html" class="code" title="function [nrm] = norm(tt)">norm</a>(H*y-[beta; 0])/normf; 
0151         y=y/beta;
0152         
0153 <span class="comment">%         y2=ww;</span>
0154 <span class="comment">%         if (y~=0)</span>
0155 <span class="comment">%             y2 = wr/y2;</span>
0156 <span class="comment">%         else</span>
0157 <span class="comment">%             y2=1;</span>
0158 <span class="comment">%         end;</span>
0159     <span class="keyword">end</span>;
0160     
0161     max_wrank=max(<a href="../../tt2/@qtt_tucker/rank.html" class="code" title="function [r]=rank(a,varargin)">rank</a>(w));
0162                 
0163     <span class="comment">%Xresid=tt_mat_to_vec(Xresid);</span>
0164     Xresid=<a href="../../tt2/@tt_tensor/tt_tensor.html" class="code" title="function t = tt_tensor(varargin)">tt_tensor</a>(Xresid);
0165     X=<a href="../../tt2/@tt_tensor/tt_tensor.html" class="code" title="function t = tt_tensor(varargin)">tt_tensor</a>(X);
0166     <span class="comment">%X=tt_mat_to_vec(X);</span>
0167     <span class="comment">%if (err&lt;err_old)</span>
0168         <span class="comment">%X = tt_axpy(1, X, y, Xresid, eps, max_rank);</span>
0169         X=<a href="../../tt2/@qtt_tucker/round.html" class="code" title="function [tt]=round(tt,varargin)">round</a>(X+y*Xresid,eps,max_rank); 
0170         
0171         <span class="comment">%err_old=err;</span>
0172     <span class="comment">%else</span>
0173     <span class="comment">%    sp=sp+1;</span>
0174     <span class="comment">%end;</span>
0175     <span class="comment">%max_xrank=max(tt_ranks(X));</span>
0176     max_xrank=max(<a href="../../tt2/@qtt_tucker/rank.html" class="code" title="function [r]=rank(a,varargin)">rank</a>(X));
0177     <span class="comment">%X = tt_vec_to_mat(X, ns, ns);</span>
0178     X=<a href="../../tt2/@tt_matrix/tt_matrix.html" class="code" title="function t = tt_matrix(varargin)">tt_matrix</a>(X,ns,ns);
0179 <span class="comment">%     if (strcmp(matvec, 'mmk2'))</span>
0180 <span class="comment">%         resid=tt_mmk2(A, X, eps, max_rank);</span>
0181 <span class="comment">%     else</span>
0182 <span class="comment">%         resid=tt_mm(A, X);</span>
0183 <span class="comment">% %         resid=tt_mat_compr(resid, eps);</span>
0184 <span class="comment">%     end;</span>
0185 <span class="comment">%     resid=ttm_add(I, tt_scal(resid, -1));</span>
0186 <span class="comment">%     resid=tt_mat_to_vec(resid);</span>
0187 <span class="comment">%</span>
0188 <span class="comment">%     err_real=sqrt(tt_dot(resid,resid))/normf;</span>
0189     err_real=0;
0190     fprintf(<span class="string">'iter [%d], res_real=%3.3e, x_rank=%d, Xr_rank=%d, w_rank=%d, err=%3.3e\n'</span>, iout, err_real, max_xrank, max_xrrank, max_wrank, err);    
0191     <span class="keyword">if</span> (err&lt;tol)||(sp&gt;0)
0192         <span class="keyword">break</span>;
0193     <span class="keyword">end</span>
0194         
0195 <span class="keyword">end</span>
0196 <span class="comment">%keyboard;</span></pre></div>
<hr><address>Generated on Wed 08-Feb-2012 18:20:24 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" title="Matlab Documentation in HTML">m2html</a></strong> &copy; 2005</address>
</body>
</html>